# Maintainer: Carlo Landmeter <clandmeter@gmail.com>
pkgname=eggdrop
pkgver=1.8.4
pkgrel=0
pkgdesc="World's most popular Open Source IRC bot"
url="https://eggheads.org/"
arch="all"
license='GPL-2.0-or-later'
options="!check" # No test suite
depends="tcl"
makedepends="openssl-dev tcl-dev !bind-libs"
subpackages="$pkgname-doc $pkgname-logs2html $pkgname-gseen"
source="$pkgname-$pkgver.tar.gz::https://github.com/eggheads/eggdrop/archive/v$pkgver.tar.gz
	eggdrop-langdir.patch
	logs2html.mod.patch
	gseen.mod.patch
	utf8.patch
	"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-tcllib=/usr/lib/libtcl8.6.so \
		--with-tclinc=/usr/include/tcl.h
	make config
	make
}

package() {
	# workaround for borked Makefile
	mkdir -p "$pkgdir"/usr/share/eggdrop/doc \
		"$pkgdir"/usr/share/eggdrop/scripts \
		"$pkgdir"/usr/share/eggdrop/help/set/

	make DEST="$pkgdir"/usr/share/eggdrop install
	rm -rf "$pkgdir"/usr/share/eggdrop/README \
		"$pkgdir"/usr/share/eggdrop/doc \
		"$pkgdir"/usr/share/eggdrop/eggdrop* \
		"$pkgdir"/usr/share/eggdrop/filesys \
		"$pkgdir"/usr/share/eggdrop/logs \
		"$pkgdir"/usr/share/eggdrop/modules \
		"$pkgdir"/usr/share/eggdrop/scripts/CONTENTS

	install -D -m 755 eggdrop "$pkgdir"/usr/bin/eggdrop
	install -D -m 644 doc/man1/eggdrop.1 \
		"$pkgdir"/usr/share/man/man1/eggdrop.1

	#move modules to /usr/lib
	mkdir "$pkgdir"/usr/lib
	mv "$pkgdir"/usr/share/eggdrop/modules-* \
		"$pkgdir"/usr/lib/eggdrop


	# Fix paths of example eggdrop.conf
	sed -i -e '2d' -e '1s@^.*@#!/usr/bin/eggdrop@' \
		-e 's@scripts/@/usr/share/eggdrop/scripts/@g' \
		-e 's@help/@/usr/share/eggdrop/help/@g' \
		-e 's@modules/@/usr/lib/eggdrop/@g' \
		eggdrop.conf

	mkdir -p "$pkgdir"/usr/share/doc/eggdrop
	cp -a \
		COPYING FEATURES NEWS README doc/Changes1.8 eggdrop.conf \
		doc/ABOUT doc/BANS doc/BOTNET doc/BUG-REPORT doc/FIRST-SCRIPT \
		doc/MODULES doc/PARTYLINE doc/TEXT-SUBSTITUTIONS doc/TRICKS \
		doc/USERS doc/WEIRD-MESSAGES doc/tcl-commands.doc doc/settings \
		doc/html \
		"$pkgdir"/usr/share/doc/eggdrop
}

logs2html() {
	pkgdesc="logs2html module for eggdrop"
	install=""
	cd "$builddir"

	for dir in language help; do
		mkdir -p "$subpkgdir"/usr/share/eggdrop/$dir
		mv "$pkgdir"/usr/share/eggdrop/$dir/logs2html.* "$subpkgdir"/usr/share/eggdrop/$dir/
	done

	mkdir -p "$subpkgdir"/usr/lib/eggdrop
	mv "$pkgdir"/usr/lib/eggdrop/logs2html.so \
		"$subpkgdir"/usr/lib/eggdrop/

	mkdir -p "$subpkgdir"/usr/share/eggdrop/log2html

	for files in logs2html.conf user.css readme.txt; do
		cp src/mod/logs2html.mod/$files "$subpkgdir"/usr/share/eggdrop/log2html/
	done
}

gseen() {
	pkgdesc="gseen module for eggdrop"
	install=""
	cd "$builddir"
	mkdir -p "$subpkgdir"/usr/share/eggdrop/language
	mv "$pkgdir"/usr/share/eggdrop/language/gseen.* \
		"$subpkgdir"/usr/share/eggdrop/language/
	mkdir -p "$subpkgdir"/usr/lib/eggdrop
	mv "$pkgdir"/usr/lib/eggdrop/gseen.so \
		"$subpkgdir"/usr/lib/eggdrop/
	mkdir -p "$subpkgdir"/usr/share/eggdrop/gseen
	cp src/mod/gseen.mod/gseen.conf "$subpkgdir"/usr/share/eggdrop/gseen/
	cp src/mod/gseen.mod/README "$subpkgdir"/usr/share/eggdrop/gseen/
}

sha512sums="80239a015f518cadc251bfc5edcf08715b9200a70eb0df7edf0efc113f320a7e407ab1fee96322fc6ec923781aa94f5a947c458e935e8a3714fb86cbcc02cb04  eggdrop-1.8.4.tar.gz
d8e8655fed028030bc3cfe28207a289d0efbc412c7e01170a4d0bb31200f7ea93df310f19e83b485013ca5d4264694b4956252663cb3a63c3d5e4cc31346e0fe  eggdrop-langdir.patch
be173d94a953c4dc5b178950d06ce894deda60c3ddb8195c836797d45fbbcc9fba3bc3d3f34c96226464fdd327093a5d15bbc2b7924d18f845738c1a4dd64a3b  logs2html.mod.patch
7879b998880deb1943c41569e243f9f1a50df23982d82d942af6c111e7fac0fb8a8444c84980645ba15b71dd69c8db2dab6f90bcb7a4292306011c7bcfc03d0d  gseen.mod.patch
7966d4d42994e44a0e571b89f1c66cb41f672d75e6ced7051d1ece23d8c209059c3565b41de950bf9c907701ce7a5e33a215b637587075ed300a002a58eda503  utf8.patch"
